<template>
	<view class="">
		<view class="c-box-nobg">
			<u-search v-model="keyword" @search="search"></u-search>
		</view>
		<view class="c-box-nobg">
			<u-swiper :list="banner" keyName="imgUrl"  indicator></u-swiper>
		</view>
		<view class="c-box-nobg">
			<c-label title="服务入口"></c-label>
		</view>
		<view class="c-box-nobg">
			<u-grid :col="5" :border="false">
				<u-grid-item v-for="item in serve" :key="item.id" @click="toServe(item.link)" class="mt16">
					<u-image :src="$http+item.imgUrl" height="80rpx" width="80rpx"></u-image>
					<text class="u-line-1" style="font-size: 23rpx;">{{item.serviceName}}</text>
				</u-grid-item>
			</u-grid>
		</view>
		<view class="c-box-nobg">
			<u-tabs :list="type" @change="tabChange"></u-tabs>
		</view>
		<view class="c-box" v-for="item in newList" :key="item.id" @click="toDetail(item.id)">
			<h3>{{item.title}}</h3>
			<view class="fl mt32">
				<view >
					<u-image :src="$http+item.cover" height="180rpx" width="220rpx" radius="10"></u-image>
				</view>
				<view class="ml32">
					<view  >
						<u-parse  :content="item.content" :domain="$http"></u-parse>
					</view>
					<view class="fl jsp mt16">
						<view class="fl alc">
							<u-icon name="chat"></u-icon>
							<text>{{item.commentNum}}</text>
						</view>
						<view class="fl alc">
							<u-icon name="clock"></u-icon>
							<text>{{item.publishDate}}</text>
						</view>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { ref,getCurrentInstance } from 'vue';
import { getSwiper,getServe, getNewType, getNewsList } from '../../api';
import {onLoad} from '@dcloudio/uni-app'
const {proxy} =getCurrentInstance()
const keyword = ref('')
const banner= ref([])
const getSwiperList = async ()=>{
	const  res =await  getSwiper()
	res.rows.map(item => {
	banner.value.push({
			imgUrl: proxy.$http + item.advImg,
			id: item.id
		})
	})
}
const search = ()=>{
	uni.navigateTo({
		url:'search/search?title='+keyword.value
	})
}
const serve = ref()
const getServeList = async ()=>{
	const res = await getServe()
	serve.value = res.rows.slice(0,10)
}
const type = ref()
const getNewstype = async ()=>{
	const res =await  getNewType()
	type.value=res.data
	getNewsListData()
	
}
const tabChange = (item)=>{
	getNewsListData(item.id)
}
const newList = ref([])
const getNewsListData =async (type)=>{
	const res = await  getNewsList(type)
	newList.value =res.rows
	newList.value.map(item=>{
		item.content = item.content.slice(0,50)
	})
}
const toDetail =(id)=>{
	uni.navigateTo({
		url:'/subpages/indexDetail/indexDetail?id='+id
	})
}
const toServe =(url)=>{
	uni.navigateTo({
		url:'/subpages/'+url
	})
}
onLoad(()=>{
	getSwiperList()
	getServeList()
	getNewstype()
})
</script>

<style lang="scss">
	
</style>